<?php
class Application_Model_shipFeeConfig extends Application_Model_DomainObject{
	
        protected $_id;//id
        protected $_cityid;//城市ID
        protected $_shipTypeId;//快递方式
        protected $_agentCompanyId;//代理公司ID
        protected $_discount;//折扣
        protected $_price;//续重价
        protected $_uuprice;//续重价
        protected $_weight;//续重
        protected $_startweight;//首重
        protected $_startPrice;//首重价
        protected $_uustartPrice;//首重价
        protected $_queryurl;//查询地址
        protected $_oil;//燃油
        protected $_clearancePrice;//报关费
        protected $_pushTime;//发布时间
        protected $_state;//状态
        protected $_times;//配送周期

        /*
         * 属性：城市名称
         */
        public  function getcityName()
        {            
            if($this->_cityid){
                $getitem=new Application_Model_city($this->_cityid);    
                return $getitem->name;
            }
            return null;
        }
        
        protected  $_city=null;
        public function getcity()
        {            
            if($this->_city==null)
            {                
                $this->_city=new Application_Model_city($this->_cityid);                    
            }            
            return $this->_city;
        }


        protected  $_ship=null;
        /*
         * 物流名称
         */
        public function  getshipTypeName(){
            if($this->_ship==null)
            {             
                if($this->_cityid){
                    $this->_city=new Application_Model_shipType($this->_shipTypeId);
                }
            }
            if($this->_city!=null)
                return $this->_city->name;
            else
                return "";
        }
        
        public function  getshipTypeImage(){
            if($this->_ship==null)
            {             
                if($this->_cityid){
                    $this->_city=new Application_Model_shipType($this->_shipTypeId);
                }
            }
            if($this->_city!=null)
                return $this->_city->image;
            else
                return "";
        }
        
        /*
         * 根据城市序号获取邮费配置信息
         */
        public function  getCityType($cityid,$typeid){
            $getItem=new Application_Model_DbTable_shipFeeConfig();
            return $getItem->getbyCityType($cityid,$typeid);
            
        }
        

        /*
         * 根据城市序号获取邮费配置信息
         */
        public static function   getbyCityid($Cityid){
            $getItem=new Application_Model_DbTable_shipFeeConfig();
            return $getItem->getbyCityid($Cityid);
        }
        
        /*
         * 根据物流公司获取区域物流信息
         */
        public static function  getbyType($typeid)
        {
            $getItem=new Application_Model_DbTable_shipFeeConfig();
            return $getItem->getbyType($typeid);
        }
        
        /*
         * 
         */
        public static function  getMoneyByCityType($cityid,$typeid,$weight)
        {
            $getItem=new Application_Model_DbTable_shipFeeConfig();
            
            $result= $getItem->getbyCityType($cityid, $typeid);
            if($result!=null){
                return $result[0]->getMoneyByweight($weight);
            }
        }
        
        //public  function getMoney($startweight,$startPrice,$weight,$price,$userweight)
        //{
            //if($startweight>=$userweight){
                //return $startPrice;
            //}
            //else{                    
                //return ($startPrice+(($userweight-$startweight)/$weight)*$price);
            //}
        //}
		public static function  getMoney($cityid,$typeid,$weight)
        {
            $getItem=new Application_Model_DbTable_shipFeeConfig();
            
            $result= $getItem->getbyCityType($cityid, $typeid);
            if($result!=null){
                return $result[0]->getMoneyByweight($weight);
            }
        }

        /*
         * 根据重量计算总费用
         */
        public  function getMoneyByweight($weight)
        { 
            if($this->_startweight>=$weight){
                return $this->_startPrice;
            }
            else if($this->_startweight<$weight){                
                $item = $this;
                $mod = ($weight-($item->startweight)) % $item->Weight;//余数
                $baishu = ($weight - $item->startweight - $mod) / $item->Weight + ($mod>0?1:0); // 倍数
                $menoy = $item->uustartPrice + $baishu *$item->uuprice;
                //return ($result[0]->uustartPrice+(($weight-($result[0]->startweight))/$result[0]->weight)*($result[0]->uuprice));
                return $menoy;
                //return $this->_startPrice+(($weight-$this->_startweight)/$this->_weight)*($this->_price);
            }
        }
}        

?>